﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using RssReader.Core.BL;

namespace RssReader.Core.UI
{
	public class BasePage : Page
	{
		#region Private Properties
		private User _currentUser;
		#endregion

		#region Public Properties
		public User CurrentUser
		{
			get
			{
				return _currentUser;
			}
		}
		#endregion

		#region Constructors

		#endregion

		#region Private Methods
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			if (Session["Email"] != null)
			{
				string email = Session["Email"].ToString();
				this._currentUser = RssReader.Core.BL.User.Load(email);
			}
		}

		protected override void OnUnload(EventArgs e)
		{
			base.OnUnload(e);
			if (_currentUser != null && _currentUser.HasChanged)
			{
				_currentUser.Save();
			}
		}
		#endregion

		#region Public Methods
		public void ThrowError(string errorMessage)
		{
			HtmlGenericControl control = this.FindControl("ErrorMessage") as HtmlGenericControl;
			if (control != null)
			{
				control.InnerHtml = errorMessage;
			}
			else
			{
				Response.Write(errorMessage);
			}
		}
		#endregion
	}
}
